package com.sgzn.sgpay.web.controller;

import com.sgzn.sgpay.model.request.SgsMobileMsgVerifyAddRequest;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.service.SgsMobileMsgVerifyService;
import com.sgzn.sgpay.web.handle.AssembleCommonHandle;
import com.sgzn.sgpay.web.request.Impl.MobileMsgVerifyAddRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 验证码控制器
 * @author Rainbow
 * @version Id: VerifyCodeCotroller.java, v 0.1 2018/5/13 21:27 Rainbow
 */
@Slf4j
@Controller
public class VerifyCodeCotroller {
    @Resource
    private SgsMobileMsgVerifyService sgsMobileMsgVerifyService;

    @Resource
    private AssembleCommonHandle assembleCommonHandle;

    /**
     * 生成验证码
     * @param request
     * @return
     */
    @RequestMapping("/verifyCode/generate")
    @ResponseBody
    public SgsResultResponse<String> generateVerifyCode(MobileMsgVerifyAddRequest request) {
        return this.sgsMobileMsgVerifyService.addMobileMsgVerify(assembleAddRequest(request));
    }

    private SgsMobileMsgVerifyAddRequest assembleAddRequest(MobileMsgVerifyAddRequest request) {
        SgsMobileMsgVerifyAddRequest sgsMobileMsgVerifyAddRequest = new SgsMobileMsgVerifyAddRequest();
        this.assembleCommonHandle.assemble(request, sgsMobileMsgVerifyAddRequest);
        sgsMobileMsgVerifyAddRequest.setMobile(request.getMobile());
        return sgsMobileMsgVerifyAddRequest;
    }
}